package com.hgd.evp.common.utils;
import java.util.Collection;
import java.util.Map;

/**
 * 判空工具类
 * @author 尚村山夫
 *
 */
public class EmptyUtil {
	/**
	 * 判断obj对象是否为空
	 * @param obj 待判断的对象
	 * @return 为空则返回true
	 */
    public static boolean isEmpty(Object obj){
        if (obj == null)
            return true;
        if (obj instanceof CharSequence)
            return ((CharSequence) obj).length() == 0;
        if (obj instanceof Collection)
            return ((Collection<?>) obj).isEmpty();
        if (obj instanceof Map)
            return ((Map<?, ?>) obj).isEmpty();
        if (obj instanceof Object[]) {
            Object[] object = (Object[]) obj;
            if (object.length == 0) {
                return true;
            }
            boolean empty = true;
            for (int i = 0; i < object.length; i++) {
                if (!isEmpty(object[i])) {
                    empty = false;
                    break;
                }
            }
            return empty;
        }
        return false;
    }
    
    /**
     * 判断obj对象不为空
     * @param obj 待判断对象
     * @return 若不为空则返回true
     */
    public static boolean isNotEmpty(Object obj){
        return !isEmpty(obj);
    }
}
